Skip to content

fix(studio): an undo or redo that adds a sealed page's first edit stays in place - #8462

Merged
miguel-heygen merged 1 commit into
mainfrom
fix/sealed-resize-redo-box
Nov 22, 2026
Merged

miguel-heygen merged 1 commit into
mainfrom
fix/sealed-resize-redo-box

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

What

In a sealed Studio preview, an undo or redo that adds an element's first Studio edit now stays on screen. Before, the redo of a resize saved the right file, but the preview kept showing the undone size until a reload landed.

Why

A sealed preview keeps Studio's size, rotation, path and motion edits applied through its seek-reapply script. That script was added to a sealed page only when its file already held one of those edits, and it did nothing on a page with none. So a redo that put back a page's first box size reached a frame with no script running. The frame refused it (restore-attributes needs a started reapply), and Studio fell back to a full reload that nothing waited for.

On main, with the sealed preview on, a logged edit-accuracy run of resize-none-px-r0-root-z100 showed the redo's restore admitted (revision 3 over 2) and the frame answering applied: false, every time. Whether the bench then sees the box wrong depends on whether the fallback reload lands before it measures: the redo box was 60 px off in 5 of 9 runs on main: 4 of 4 at two parallel jobs, 1 of 2 at one job, 0 of 3 at one job with screenshots on. The unsealed preview never hits this: Studio installs its own reapply in a frame it can reach.

Related work

Refs #7846 (Studio's preview sealed by default). Its edit-accuracy gate has a sealed-only undo row this clears for resize.

How

  • opaqueFrameLoads.ts: every sealed page carries the seek-reapply script, whether or not its file has a Studio edit yet. Studio can't add it once a sealed page has loaded.
  • manualEditsRenderScript.ts: in a sealed frame (followFrames), the script stays armed on a page with no edit and reapplies whatever marks exist at each seek. The render and unsealed script (createStudioPositionSeekReapplyScript) keeps its early return, so renders don't change.
  • Renders never go through this: opaqueFrameLoads rewrites only HTML served under preview/~<token>/, which only Studio's sealed frames load. The producer adds its own copy (htmlCompiler.ts), and the sealed script returns at once in a top-level window.
  • Next step, in its own PR once the sealed preview is the default: the unsealed preview moves onto the same in-frame script, and Studio's own copy (reapplyPositionEditsAfterSeek, installManualEditReapply) is deleted. It stays out of this PR because Studio calls that copy synchronously at selection, DOM-edit sync and load, not only on seeks, so moving it changes the unsealed preview's timing.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments"

fails without the fix:

  • manualEditsRenderScript.test.ts "keeps a %s mark a restore adds to a sealed page that loaded with none": one row each for box-size, rotation, path-offset and motion. A sealed page loads with no edit, a restore adds the mark, and the next frame puts it back.
  • preview.opaqueFrameLoads.test.ts "puts Studio's seek reapply last in every sealed document, edited or not, and in no plain one".

Both files pass three runs in a row on Linux (93 tests). Pre-commit passes: lint, format, fallow, typecheck.

Edit-accuracy bench, sealed preview on (VITE_STUDIO_OPAQUE_PREVIEW_ENABLED=true), 8 resize cases (none, spin, hold, scale, fromto, seqresize), 3 runs: the undo check (undo and redo bytes identical, box within 0.5 px) passes in all 24, redo box 0 px. On main the same redo is refused every run (see Why). Other metrics in these cases are outside this change.

Cost on a page with no Studio edit (500 elements, Chrome 158 headless, median of 5):

Preview Script Wrapped seek Per frame, playhead moving
sealed main 0.0003 ms 0 (not running)
sealed this PR 0.0010 ms 0.032 ms
unsealed main 0.0003 ms 0
unsealed this PR 0.0004 ms 0

Not exercised: a full gate run of #7846 with this merged; the other sealed undo rows (lost undos in held and fast key sequences) have their own root.

Before: main, sealed preview, right after Redid: Resize layer box — the box still shows the undone size

After: this branch, same moment — the box is back at its resized size

…ys in place

A sealed preview only got its seek-reapply script when its file already held a Studio edit, and the script left
a page with none unarmed. The first restore that added one (a redo of a resize, say) was refused by the frame
and fell back to an unawaited reload. Every sealed page now carries the script, armed from the start.
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 71 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. I reviewed at 48feecd0.

Need ✅ · Size ✅ (+65 −9) · Reuse ✅ · Simpler ✅ · Structure ✅
Risk: low. Only HTML served under preview/~<token>/ gets the script, and only Studio's sealed frames load that. The render and unsealed script keeps its early return.

What I checked:

  • withSeekReapplyArmedForAnyEdit still runs only on 200 text/html responses. A plain (non-iframe) load still gets no script.
  • The sealed wrapper returns at once in a top-level or same-origin window.
  • htmlHasStudioPositionEdits is still used by the producer (htmlCompiler.ts:2743), so dropping its import here leaves nothing dead.
  • The per-frame cost on a page with no edit is measured in the body: 0.032 ms with the playhead moving, sealed only.
  • The two touched suites pass, 93/93, and tsc --noEmit on studio-server is clean.
  • fails without the fix: confirmed. With both helpers as on main, 5 tests fail: the four "keeps a … mark a restore adds to a sealed page that loaded with none" rows, plus the sealed-document test in preview.opaqueFrameLoads.test.ts.

— Rames (hf-review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit 2d72e52 Nov 22, 2026
195 of 196 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-resize-redo-box branch November 22, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants